package org.ksoap2.serialization;

import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;

/* loaded from: classes2.dex */
class DM implements Marshal {
    @Override // org.ksoap2.serialization.Marshal
    public Object readInstance(XmlPullParser xmlPullParser, String str, String str2, PropertyInfo propertyInfo) throws IOException, XmlPullParserException {
        String nextText = xmlPullParser.nextText();
        char charAt = str2.charAt(0);
        if (charAt != 'b') {
            if (charAt != 'i') {
                if (charAt != 'l') {
                    if (charAt == 's') {
                        return nextText;
                    }
                    throw new RuntimeException();
                }
                return new Long(Long.parseLong(nextText));
            }
            return new Integer(Integer.parseInt(nextText));
        }
        return new Boolean(SoapEnvelope.stringToBoolean(nextText));
    }

    @Override // org.ksoap2.serialization.Marshal
    public void writeInstance(XmlSerializer xmlSerializer, Object obj) throws IOException {
        int i = 0;
        if (obj instanceof AttributeContainer) {
            AttributeContainer attributeContainer = (AttributeContainer) obj;
            int attributeCount = attributeContainer.getAttributeCount();
            while (i < attributeCount) {
                AttributeInfo attributeInfo = new AttributeInfo();
                attributeContainer.getAttributeInfo(i, attributeInfo);
                try {
                    attributeContainer.getAttribute(i, attributeInfo);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (attributeInfo.getValue() != null) {
                    xmlSerializer.attribute(attributeInfo.getNamespace(), attributeInfo.getName(), attributeInfo.getValue() != null ? attributeInfo.getValue().toString() : "");
                }
                i++;
            }
        } else if (obj instanceof HasAttributes) {
            HasAttributes hasAttributes = (HasAttributes) obj;
            int attributeCount2 = hasAttributes.getAttributeCount();
            while (i < attributeCount2) {
                AttributeInfo attributeInfo2 = new AttributeInfo();
                hasAttributes.getAttributeInfo(i, attributeInfo2);
                try {
                    hasAttributes.getAttribute(i, attributeInfo2);
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
                if (attributeInfo2.getValue() != null) {
                    xmlSerializer.attribute(attributeInfo2.getNamespace(), attributeInfo2.getName(), attributeInfo2.getValue() != null ? attributeInfo2.getValue().toString() : "");
                }
                i++;
            }
        }
        if (obj instanceof ValueWriter) {
            ((ValueWriter) obj).write(xmlSerializer);
        } else {
            xmlSerializer.text(obj.toString());
        }
    }

    @Override // org.ksoap2.serialization.Marshal
    public void register(SoapSerializationEnvelope soapSerializationEnvelope) {
        soapSerializationEnvelope.addMapping(soapSerializationEnvelope.xsd, "int", PropertyInfo.INTEGER_CLASS, this);
        soapSerializationEnvelope.addMapping(soapSerializationEnvelope.xsd, "long", PropertyInfo.LONG_CLASS, this);
        soapSerializationEnvelope.addMapping(soapSerializationEnvelope.xsd, "string", PropertyInfo.STRING_CLASS, this);
        soapSerializationEnvelope.addMapping(soapSerializationEnvelope.xsd, "boolean", PropertyInfo.BOOLEAN_CLASS, this);
    }
}
